#include "Object.hpp"


void Object::attach() { 
  m_iterator = ObjectGestionner::attachObject(this);
};

void Object::erase() {
  //ObjectGestionner::detachObject(m_iterator);
};


void Object::addModificationListener(ModificationListener* ml_) {
	list<ModificationListener*>::iterator it = m_modificationListenerList.begin();
	ml_->setModificationIterator(m_modificationListenerList.insert(it, ml_));
};

glm::mat4 Object::getPositionMatrix() {
	const glm::vec3 X_AXIS(1.0f,0.0f,0.0f);
	const glm::vec3 Z_AXIS(0.0f,0.0f,1.0f);
	glm::mat4 tmp = glm::mat4();
	glm::vec3 gp = m_mainNode->getPosition();
	tmp = glm::translate(tmp,gp);
	tmp = glm::rotate<GLfloat>(tmp,m_mainNode->getAngle(),Z_AXIS);
	return tmp; 
};


vec3 Object::getDirection() {
	vec4 tmp = glm::rotate<GLfloat>(vec4(1.0f, 0.0f, 0.0f,1.0),m_mainNode->getAngle(),vec3(0.0f, 0.0f, 1.0f));
	vec3 dir(tmp.x, tmp.y, tmp.z);
	dir /= tmp.w;
	return dir;//vec3(v.x, v.y, v.z);
};

/************************* OBJECT_GESTIONNER PART ***************************/


list<Object*> ObjectGestionner::m_objectList;
